# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: Sean McAvoy <seanmcavoy@gmail.com>
pkgname=distrobuilder
pkgver=3.1
pkgrel=0
pkgdesc="System container image builder"
url="https://linuxcontainers.org/distrobuilder/"
arch="all !armhf !armv7"
license="Apache-2.0"
depends="gnupg xz"
makedepends="go linux-headers"
subpackages="$pkgname-lxc::noarch $pkgname-lxd::noarch $pkgname-incus::noarch $pkgname-doc"
checkdepends="squashfs-tools"
options="net"
source="https://github.com/lxc/distrobuilder/archive/refs/tags/distrobuilder-$pkgver.tar.gz"
builddir="$srcdir/distrobuilder-distrobuilder-$pkgver"
options="net"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"
export GOFLAGS="$GOFLAGS -modcacherw"

build() {
	go build -o out ./distrobuilder
}

check() {
	# FIXME: skip some failing tests
	go test -v -skip "TestIncus*|TestGetLatestRelease" ./...
}

package() {
	install -Dm755 out "$pkgdir"/usr/bin/$pkgname
	install -Dm644 -t "$pkgdir"/usr/share/doc/distrobuilder doc/*.md
	install -Dm644 -t "$pkgdir"/usr/share/doc/distrobuilder/examples doc/examples/*.yaml
}

lxc() {
	pkgdesc="$pkgdesc (for LXC)"
	depends="$pkgname"
	install_if="$pkgname=$pkgver-r$pkgrel lxc"
	mkdir -p "$subpkgdir"
}

lxd() {
	pkgdesc="$pkgdesc (for LXD)"
	depends="$pkgname squashfs-tools"
	install_if="$pkgname=$pkgver-r$pkgrel lxd"
	mkdir -p "$subpkgdir"
}

incus() {
	pkgdesc="$pkgdesc (for incus)"
	depends="$pkgname squashfs-tools"
	install_if="$pkgname=$pkgver-r$pkgrel incus"
	mkdir -p "$subpkgdir"
}

sha512sums="
d5f7277cada70105e3bfb0bfb13778cf323d58e384c54a9674cad6539373d0888f3360997edb5fe8a306ae131e2ab7042aba496e1cfdb2a146f0a0e0ec059af2  distrobuilder-3.1.tar.gz
"
